package com.yuexunit.operationman.nbsy.module.InterventionalOperation.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.Bean.InterNursingBean;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.InterNurseContracts;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.model.impl.InterNursingDetailModel;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.presenter.IInterNursingDetailPresenter;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.presenter.impl.InterNursingDetailPresenter;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.ui.view.IInterNurseDetailView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/7/24 0024.
 */

public class Act_InterventionalOperation_Main extends BaseKJActivity implements IInterNurseDetailView{

    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.pic)
    ImageView pic;
    @Bind(R.id.name)
    TextView name;
    @Bind(R.id.age)
    TextView age;
    @Bind(R.id.sex)
    TextView sex;
    @Bind(R.id.admission_number)
    TextView admissionNumber;
    @Bind(R.id.opration_name)
    TextView oprationName;
    @Bind(R.id.clinical_diagnosis)
    TextView clinicalDiagnosis;
    @Bind(R.id.afteroperationmain_doc)
    TextView afteroperationmainDoc;

    IInterNursingDetailPresenter presenter;

    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_interventionaloperation_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new InterNursingDetailPresenter(this,new InterNursingDetailModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        presenter.getInterNurseDate(params);
    }

    private void setTitle()
    {
        titlebarTvTitle.setText("局部麻醉记录单");
    }


    @OnClick({R.id.titlebar_img_back, R.id.operation_nursing, R.id.preview})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.operation_nursing:
                startActivity(new Intent(aty, Act_InterventionalOperation_Infor.class));
                break;
            case R.id.preview:
                startActivity(new Intent(aty, Act_InterventionalOperation_Preview.class));
                break;
        }
    }

    @Override
    public void getInterNurseDate(InterNursingBean interNursingBean) {
        if(interNursingBean.getCode() == 200)
        {
            AppConfig.INTERNURSEBEAN =interNursingBean;
            name.setText(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getPatientName());
            age.setText(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getPatientAge()+"");
            if(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getPatientSex().equals("1")) {
                sex.setText("男");
            }else if(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getPatientSex().equals("2"))
            {
                sex.setText("女");
            }
            else {
                sex.setText("不详");
            }
            admissionNumber.setText(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getInHospitalNo());
            oprationName.setText(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getOperationName());
            clinicalDiagnosis.setText(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getClinicalDiagnosis());
            afteroperationmainDoc.setText(AppConfig.INTERNURSEBEAN.getObject().getInterNursing().getOperationAfterDesc());
            if(AppConfig.INTERNURSEBEAN.getObject().getInterNursingItemList() == null)
            {
                AppConfig.INTERNURSEBEAN.getObject().setInterNursingItemList(InterNurseContracts.interNursingItemListEntities(this));
            }
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
